<template>
    <user-selector-plus ref="userSelectorPlusRef" :org-tree-api="selectorApiFunction.orgTreeApi"
        :user-page-api="selectorApiFunction.userPageApi" :checked-user-list-api="selectorApiFunction.checkedUserListApi"
        :radio-model="props.radioModel" @onBack="userBack" />
    <!-- test -->
</template>

<script setup>
import orgApi from '@/api/sys/orgApi'
import userCenterApi from '@/api/sys/userCenterApi'
import UserSelectorPlus from './userSelectorPlus.vue'
// import props from '../DragModal/props';
let userSelectorPlusRef = ref()
const formData = ref({})
const props = defineProps({
    radioModel: {
        type: Boolean,
        default: true
    }
})

const emits = defineEmits(['OnClose'])
// 人员选择器回调
const userBack = (value) => {
    console.log('userBack', value)
    // if (value.length > 0) {
    if (!props.radioModel) {
        emits('OnClose', value)
    } else {
        formData.value.directorId = value[0].id
        formData.value.directorName = value[0].name
        emits('OnClose', formData)
    }
    // } else {
    //     formData.value.directorId = ''
    //     formData.value.directorName = ''
    // }
}
// 传递设计器需要的API
const selectorApiFunction = {
    orgTreeApi: (param) => {
        return orgApi.orgOrgTreeSelector(param).then((data) => {
            return Promise.resolve(data)
        })
    },
    userPageApi: (param) => {
        return orgApi.orgUserSelector(param).then((data) => {
            return Promise.resolve(data)
        })
    },
    checkedUserListApi: (param) => {
        return userCenterApi.userCenterGetUserListByIdList(param).then((data) => {
            return Promise.resolve(data)
        })
    }
}
const show = (id) => {
    var checkedUserIds = []
    if (typeof id === 'object') {
        checkedUserIds = id;
    } else {
        checkedUserIds.push(id)
    }

    userSelectorPlusRef.value.showUserPlusModal(checkedUserIds)
}
defineExpose({
    show
})
</script>